name: update-saas-backend

# Deploy backend only if push on "main"
on:
  push:
    branches: [main, develop]
    paths:
      - "twake/docker/**"
      - "twake/backend/**"
      - ".github/workflows/**"

jobs:
  deploy-php:
    runs-on: ubuntu-20.04
    steps:
      - name: Set env to develop
        if: endsWith(github.ref, '/develop')
        run: 'echo "DOCKERTAG=develop" >> $GITHUB_ENV'
      - name: Set env to production
        if: endsWith(github.ref, '/main')
        run: 'echo "DOCKERTAG=latest" >> $GITHUB_ENV'
      - uses: actions/checkout@v2
      - name: Publish to Registry
        uses: elgohr/Publish-Docker-Github-Action@master
        with:
          name: twaketech/twake-php
          username: ${{ secrets.DOCKER_USERNAME }}
          password: ${{ secrets.DOCKER_PASSWORD }}
          workdir: twake
          buildoptions: "-t twaketech/twake-php -f docker/twake-php/Dockerfile"
          tags: "${{ env.DOCKERTAG }}"
